package com.gp.library.utils;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

public class InputMethodUtils {

    public static void hideInputMethod(Activity activity) {
        if (activity == null)
            return;
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
    }

    public static void hideInputMethod(View viwe) {
        if (viwe == null || viwe.getContext() == null)
            return;
        InputMethodManager imm = (InputMethodManager) viwe.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(viwe.getWindowToken(), 0);
    }


    protected static void showInputMethod(View v) {
        if (v == null || v.getContext() == null)
            return;
        InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(v, InputMethodManager.SHOW_FORCED);
//        imm.showSoftInput(v, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
